#ifndef SUB_SYSTEM_H
#define SUB_SYSTEM_H

#include <iostream>
#include <string>
#include <chrono>
#include <thread>
const std::string c_stateToStrCourier[] = { "receive", "verify accessibility", "assign people", "delivery packages", "obtain delivery confirmation", "done" };
const std::string c_stateToStrVendor[] = { "receive", "confirm inventory", "get goods from warehouse", "packing", "contact the courier", "done" };
const std::string c_stateToStrOrderTeam[] = { "receive", "confirm payment", "contact supplier", "done" };
const int c_nMsec = 300;  // 休眠时间(毫秒)
// 订单团队
class OrderTeam
{
public:
    void submitRequest() {
        m_nState = 0;
    }

    // 检测状态
    bool checkStatus() {
        std::cout << "Order team - current status:" << c_stateToStrOrderTeam[m_nState] << std::endl;
        std::this_thread::sleep_for(std::chrono::milliseconds(c_nMsec));
        m_nState++;

        return (m_nState == Complete);
    }

private:
    enum States {
        Received,  // 收到
        VerifyPayment,  // 确认付款
        ContactVendor,  // 联系供应商
        Complete  // 完成
    };
    int m_nState;
};

// 供应商
class Vendor
{
public:
    void submitRequest() {
        m_nState = 0;
    }

    // 检测状态
    bool checkStatus() {
        std::cout << "Supplier - current status:" << c_stateToStrVendor[m_nState] << std::endl;

        std::this_thread::sleep_for(std::chrono::milliseconds(c_nMsec));
        m_nState++;

        return (m_nState == Complete);
    }

private:
    enum States {
        Received,  // 收到
        VerifyInventory,  // 确认库存
        GetItemFromWareHouse,  // 从仓库得到物品
        PackItem,  // 包装
        ContactCourier,  // 联系快递员
        Complete  // 完成
    };
    int m_nState;
};

// 快递员
class Courier
{
public:
    // 将请求转发给快递员
    void submitRequest() {
        m_nState = 0;
    }

    // 检测状态
    bool checkStatus() {
        std::cout << "Courier - current status:" << c_stateToStrCourier[m_nState] << std::endl;

        std::this_thread::sleep_for(std::chrono::milliseconds(c_nMsec));
        m_nState++;

        return (m_nState == Complete);
    }

private:
    enum States {
        Received,  // 收到
        VerifyReachbility,  // 验证可达性
        AssignPerson,  // 分配人员
        DispatchPackage,  // 派送包裹
        GetDeliveryConfirmation,  // 获取交货确认
        Complete  // 完成
    };
    int m_nState;
};

#endif // SUB_SYSTEM_H
